import router from "@/router"

export default {
  "SET_breadcrumb"(state, data) {
    state.breadcrumb = data.matched;
  },
  "SET_menuIndex"(state, data) {
    state.menuIndex = data.path;
    state.menuIndexName = data.name;
  },
  "ADD_menuTabs"(state, data) {
    let boo = false;
    state.menuTabs.forEach(item => {
      if (item.meta.title == data.meta.title) {
        boo = true;
      }
    });
    if (boo) return;
    if(data.path == "/login") return;
    state.menuTabs.push(data);
    state.menuTabsArr.push(data.name);
  },
  "DEL_menuTabs"(state, data) {
    if ((data.path == "/welcome" || data.path == "/") && state.menuTabs.length == 1) return;
    state.menuTabs.splice(data.index, 1);
    state.menuTabsArr.splice(data.index, 1);
    // 删除 当前页
    if (data.path == state.menuIndex) {
      if (data.index < state.menuTabs.length) {
        router.push(state.menuTabs[data.index].path);
      } else if (data.index != 0) {
        router.push(state.menuTabs[data.index - 1].path);
      } else {
        router.push("/");
      }
    }
  }


}